﻿using AutoMapper;
using MediatR;
using PersonnelManagement.Application.Command.ClientCommand;
using PersonnelManagement.Application.Command.ManpowerCommand;
using PersonnelManagement.Domain.PersonnelDomain;
using PersonnelManagement.Infrstructre.Interface;

namespace PersonnelManagement.Application.CommandHandler.ClientCommandHandlers
{
    public class ClientUpdmandHandlers : IRequestHandler<ClientUpdCommand, int>
    {
        IClientRepository cRep;
        IMapper mapper;

        public ClientUpdmandHandlers(IClientRepository cRep, IMapper mapper)
        {
            this.cRep = cRep;
            this.mapper = mapper;
        }
        public async Task<int> Handle(ClientUpdCommand request, CancellationToken cancellationToken)
        {
            var list = (await cRep.Getall()).Where(x => x.ClientId == request.UpdDtos.ClientId).First();
            list.ClientId=request.UpdDtos.ClientId;
            list.ClientName = request.UpdDtos.ClientName;
            list.ClientNumber = request.UpdDtos.ClientNumber;
            list.CId = request.UpdDtos.CId;
            list.CFUmanner = request.UpdDtos.CFUmanner;
            list.ProvinceId = request.UpdDtos.ProvinceId;
            list.CityId = request.UpdDtos.CityId;
            list.CSourceWay = request.UpdDtos.CSourceWay;
            list.CIndustry = request.UpdDtos.CIndustry;
            list.CustomerValue = request.UpdDtos.CustomerValue;
            list.CreditRating = request.UpdDtos.CreditRating;
            list.CompanyAddress = request.UpdDtos.CompanyAddress;
            list.CompanyProfile = request.UpdDtos.CompanyProfile;
            list.CPrimaryContact = request.UpdDtos.CPrimaryContact;
            list.CGender = request.UpdDtos.CGender;
            list.CDepartment = request.UpdDtos.CDepartment;
            list.CPhone = request.UpdDtos.CPhone;
            list.CPickingStatus = request.UpdDtos.CPickingStatus;
            list.CApplicant = request.UpdDtos.CApplicant;
            list.CRecipients = request.UpdDtos.CRecipients;
            list.CPickTime = request.UpdDtos.CPickTime;
            //list.AddName = request.UpdDtos.AddName;
            //list.AddTime = request.UpdDtos.AddTime;
            list.UpdName = request.UpdDtos.UpdName;
            list.UpdTime = request.UpdDtos.UpdTime;
            //list.DelName = request.UpdDtos.DelName;
            //list.DelTime = request.UpdDtos.DelTime;
            //list.IsDel = request.UpdDtos.IsDel;
            //list.Office_Id = request.UpdDtos.Office_Id;
            //list.User_Id = request.UpdDtos.User_Id;
             await cRep.UpdateAsymc(list);
            return 1;
        }
    }
}
